package NewCoder;

import java.util.ArrayList;

public class BM74 {
    private String nums="";
    public ArrayList<String> restoreIpAddresses (String s) {
        // write code here
        ArrayList<String> list=new ArrayList<>();
        dfs(s,list,0,0);
        return list;
    }

    //step表示几个数字 index表示遍历到的下标
    private void dfs(String s, ArrayList<String> list, int step , int index){
        String cur="";
        if(step==4){
            if(index!=s.length()){
                return;
            }
            list.add(nums);
        }
        for(int i=index;i<index+3 && i<s.length();i++){
            cur+=s.charAt(i);
            int num=Integer.parseInt(cur);
            String temp=nums;
            if(num<=255 && (cur.length()==1 || cur.charAt(0)!='0')){
                if(step-3!=0){
                    nums+=cur+".";
                }else{
                    nums+=cur;
                }
                dfs(s,list,step+1,i+1);
                nums=temp;
            }

        }
    }
}
